import { describe, it, expect } from 'vitest';
import { getSysRouteMap, mergeServerRoute } from '../routeUtils';

describe('routeUtils', () => {
    describe('getSysRouteMap', () => {
        it('should return system route map with correct structure', () => {
            const routeMap = getSysRouteMap();

            expect(routeMap).toHaveProperty('chat');
            expect(routeMap).toHaveProperty('403');
            expect(routeMap).toHaveProperty('404');

            expect(routeMap.chat).toHaveProperty('path', '/chat');
            expect(routeMap.chat).toHaveProperty('name', 'chat');
            expect(routeMap.chat).toHaveProperty('component');
            expect(routeMap.chat.meta).toHaveProperty('title', '聊天');
        });
    });

    describe('mergeServerRoute', () => {
        it('should handle empty server menus', () => {
            const result = mergeServerRoute([], getSysRouteMap());
            expect(result).toEqual([]);
        });

        it('should handle invalid server menus', () => {
            const result = mergeServerRoute(null as any, getSysRouteMap());
            expect(result).toEqual([]);
        });

        it('should merge server menus with system routes', () => {
            const serverMenus = [
                {
                    name: 'chat',
                    path: '/chat',
                    title: '聊天页面',
                    icon: 'chat-icon'
                }
            ];

            const result = mergeServerRoute(serverMenus, getSysRouteMap());

            expect(result).toHaveLength(1);
            expect(result[0]).toHaveProperty('name', 'chat');
            expect(result[0]).toHaveProperty('path', '/chat');
            expect(result[0]).toHaveProperty('component');
            expect(result[0].meta).toHaveProperty('title', '聊天页面');
            expect(result[0].meta).toHaveProperty('icon', 'chat-icon');
        });

        it('should handle nested menus', () => {
            const serverMenus = [
                {
                    name: 'parent',
                    path: '/parent',
                    title: '父菜单',
                    children: [
                        {
                            name: 'child',
                            path: '/child',
                            title: '子菜单'
                        }
                    ]
                }
            ];

            const result = mergeServerRoute(serverMenus, getSysRouteMap());

            expect(result).toHaveLength(1);
            expect(result[0]).toHaveProperty('children');
            expect(result[0].children).toHaveLength(1);
            expect(result[0].children[0]).toHaveProperty('name', 'child');
        });
    });
});